package com.gwnet.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.domain.GoodsSpec;
import com.gwnet.shop.service.IGoodsSpecService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 就是聊天呀  微信号
 * @author 张万鹏
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/spec")
public class GoodsSpecController extends MBaseController
{
    @Resource
    private IGoodsSpecService goodsSpecService;

    /**
     * 查询商品规格名称列表
     * goodsSpec 商品规格,一个商品会有多种规格,一种规格下又会有若干子规格, 每个商品最多添加两种规格
     * goodsGroup
     */
    @SaCheckPermission("shop:spec:list")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSpec goodsSpec)
    {
        startPage();
        List<GoodsSpec> list = goodsSpecService.selectGoodsSpecList(goodsSpec);
        return getDataTable(list);
    }


    /**
     * 获取商品规格名称详细信息
     */
    @SaCheckPermission("shop:spec:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsSpecService.selectGoodsSpecById(id));
    }

    /**
     *abcd
     * 新增商品规格名称
     */
    @SaCheckPermission("shop:spec:add")
    @Log(title = "商品规格名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsSpec goodsSpec)
    {
        goodsSpec.setCreateBy( LoginHelper.getUserId() );
        return toAjax(goodsSpecService.insertGoodsSpec(goodsSpec));
    }

    /**
     * 修改商品规格名称
     */
    @SaCheckPermission("shop:spec:edit")
    @Log(title = "商品规格名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsSpec goodsSpec)
    {
        goodsSpec.setCreateBy( LoginHelper.getUserId() );
        return toAjax(goodsSpecService.updateGoodsSpec(goodsSpec));
    }

    /**
     * 删除商品规格名称
     */
    @SaCheckPermission("shop:spec:remove")
    @Log(title = "商品规格名称", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsSpecService.deleteGoodsSpecByIds(ids));
    }
}
